<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //浅拷贝数组
        let arr1 = [1, 2, 3];
        let arr2 = arr1; // 浅拷贝
        arr2[0] = 4; // 修改arr2的第一个元素
        console.log(arr1); // [4, 2, 3]
        console.log(arr2); // [4, 2, 3]
        //浅拷贝对象
        let person = {
            name: '张三',
            age: 18,
            eat() {
                console.log(`${this.age}岁的${this.name}在吃饭`);
            }
        };
        let person1 = person;
        person1.name = '李四'; // 修改person1的name属性
        console.log(person.name); // 张三
        //深拷贝数组
        let arr3=[1,2,3];
        let arr4=[...arr3]; // 浅拷贝
        arr2[0] = 4; // 修改arr2的第一个元素
        console.log(arr3); // [1, 2, 3]
        console.log(arr4); // [4, 2, 3]
        //深拷贝对象
        let person2 =JSON.parse(JSON.stringify(person))
        person2.name = '王五'; // 修改person2的name属性
        console.log(person.name); // 张三
        
    </script>
</head>

<body>

</body>

</html>